<template>
  <div class="app-container">
    <el-row :gutter="20">
      <div class="filter-container">
        <el-col :span="4">
          <el-col :span="1">
            <i :class="[treeShow ? 'el-icon-s-fold treeI': 'el-icon-s-unfold treeI']" @click="toggerTree" />
          </el-col>
        </el-col>
        <el-col style="text-align:right;margin-top: -8px;margin-bottom:10px" :span="20">
          <el-button
            size="small"
            class="filter-item"
            style="margin-left: 10px;"
            type="primary"
            @click="handleQuery"
          >
            额度刷新
          </el-button>
          <el-button
            size="small"
            font-size="14px"
            class="filter-item"
            style="margin-left: 10px;"
            type="primary"
            @click="handleHookUp"
          >
            指标挂接
          </el-button>
        </el-col>
      </div>
    </el-row>
    <div class="grid-content bg-purple" />
    <div
      ref="box"
      class="box"
    >
      <div
        class="left"
        :class="[isActive ? 'wid':'wids']"
      >
        <div
          :class="[treeShow ? 'treeShow' : 'treeNotShow']"
          :style="{'height' : treeHeight + 'px'}"
        >
          <AgencyTree class="agencyTree" @handleTreeQuery="handleTreeQuery" @getFirstAuthAgencyData="getFirstAuthAgencyData" />
        </div>
      </div>
      <div
        v-show="Show"
        class="resize"
        title="收缩侧边栏"
      />
      <div
        class="mid"
        :class="[isActive ? 'mids': 'min']"
      >
        <!-- 表格部分 -->
        <el-table
          ref="singalTable"
          v-loading="listLoading"
          :data="list"
          :stripe="true"
          :height="tableHeight"
          fit
          style="width: 100%;  margin-left:10px"
          :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        >
          <template slot="empty">
            <tableEmpty />
          </template>
          <el-table-column type="selection" align="center" width="50" />
          <el-table-column type="index" align="center" width="50" label="序号" />
          <el-table-column label="工资项名称" prop="salaryBaseName" align="center" />
          <el-table-column label="工资类别" prop="personStateName" align="center" />
          <!-- <el-table-column label="状态" align="center">
            <template slot-scope="{row}">
              <span>{{ row.isUsing | usingFilter() }}</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="指标ID" prop="bgtId" align="center" />
          <el-table-column label="指标文号" prop="corBgtDocNoName" align="center" /> -->
          <el-table-column label="指标总额" align="center">
            <template slot-scope="{row}">
              <span style="float: right">{{ Number(row.aviamt).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="可用指标额" align="center">
            <template slot-scope="{row}">
              <span style="float: right">{{ Number(row.canuseamt).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="支付方式" prop="payTypeName" align="center" />
          <el-table-column label="资金性质" prop="fundTypeName" align="center" />
          <el-table-column label="年度" prop="year" align="center" /> -->
          <el-table-column label="单位编码" prop="agencyCode" align="center" />
          <el-table-column label="单位名称" prop="agencyName" align="center" />
        </el-table>
        <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
      </div>
    </div>
    <Drag ref="icon" />
    <!-- 指标挂接 -->
    <el-dialog  v-dialogDrag   title="指标挂接" :visible.sync="hookUpFormVisible" width="70%" :close-on-click-modal="false">
      <el-form ref="hookUpForm" :model="formData" label-position="right" label-width="120px" size="small">
        <el-row class="el-row-out">
          <el-col :span="8">
            <el-row>
              <el-tree
                ref="treee"
                node-key="code"
                :highlight-current="true"
                :accordion="true"
                show-checkbox
                :data="agencyTreeData"
                :props="defaultPropss"
                class="el-tree-out"
                style="height: 999px; margin-right: 10px"
                :default-expanded-keys="['0']"
              />
            </el-row>
          </el-col>
          <el-col :span="16">
            <el-row>
              <el-col>
                <span style="font-weight: 600">工资项目：</span>
              </el-col>
            </el-row>
            <el-row style="border: 1px solid #f2f2f2; margin-top: 1%">
              <el-col :span="5.5">
                <el-form-item label="工资项名称" style="background-color: #f2f2f2" />
                <el-select v-model="tmpData.columnNames" class="filter-item" multiple clearable placeholder="--请选择--" style="width:100%" @change="getSalary">
                  <el-option v-for="item in salaryData" :key="item.salaryCode" :label="item.salaryName" :value="item.salaryCode" />
                </el-select>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="工资项类别" style="background-color: #f2f2f2" />
                <el-select v-model="tmpData.personType" class="filter-item" clearable placeholder="--请选择--" style="width:100%">
                  <el-option v-for="item in personTypeData" :key="item.personTypeCode" :label="item.personTypeName" :value="item.personTypeCode" />
                </el-select>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <span style="font-weight: 600">指标筛选规则：</span>
              </el-col>
            </el-row>
            <el-row style="border: 1px solid #f2f2f2; margin-top: 1%">
              <!-- <el-col :span="5.5">
                <el-form-item label="项目分类" style="background-color: #f2f2f2" />
                <el-select v-model="formData.proCatCode" class="filter-item" clearable placeholder="--请选择--" style="width:100%">
                  <el-option v-for="item in proCatLists" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-col> -->
              <el-col :span="5.5">
                <el-form-item label="预算项目" style="background-color: #f2f2f2" />
                <el-input v-model="formData.proCode" clearable/>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="指标文号" style="background-color: #f2f2f2" />
                <el-input v-model="formData.corBgtDocNoName" clearable/>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="支付方式" style="background-color: #f2f2f2" />
                <el-select v-model="formData.payTypeCode" class="filter-item" clearable placeholder="--请选择--" style="width:100%">
                  <el-option v-for="item in payTypeLists" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="支出功能科目" style="background-color: #f2f2f2" />
                <el-select ref="selectFuncReport" v-model="funcName" class="filter-item" clearable placeholder="--请选择--" style="width:100%" @clear="clearHandlePay">
                  <el-option :value="formData.funcCode" :label="funcName" style="height:200px;overflow: auto;background-color:#fff">
                    <el-tree
                      :data="funcLists"
                      :accordion="true"
                      :highlight-current="true"
                      :props="defaultProps"
                      :node-key="defaultProps.id"
                      :default-expanded-keys="defaultExpandedKey"
                      @node-click="handleFuncNodeClick"
                    />
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="经济分类" style="background-color: #f2f2f2" />
                <el-select ref="selectReport" v-model="depBgtEcoName" class="filter-item" clearable placeholder="--请选择--" style="width:100%" @clear="clearHandle">
                  <el-option :value="formData.depBgtEcoCode" :label="depBgtEcoName" style="height:200px;overflow: auto;background-color:#fff">
                    <el-tree
                      :data="depBgtEcoLists"
                      :accordion="true"
                      :highlight-current="true"
                      :props="defaultProps"
                      :node-key="defaultProps.id"
                      :default-expanded-keys="defaultExpandedKey"
                      @node-click="handleNodeClick"
                    />
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="支出类别" style="background-color: #f2f2f2" />
                <el-select ref="selectPayReport" v-model="payCategoryName" class="filter-item" clearable  style="width:100%"  @clear="clearPayHandle">
                  <el-option :value="formData.payCategoryCode" :label="payCategoryName" style="height:200px;overflow: auto;background-color:#fff">
                    <el-tree
                      :data="payCategoryLists"
                      :accordion="true"
                      :highlight-current="true"
                      :props="defaultProps"
                      :node-key="defaultProps.id"
                      :default-expanded-keys="defaultPayExpandedKey"
                      @node-click="handlePayNodeClick"
                    />
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="政府经济科目" style="background-color: #f2f2f2" />
                <el-select ref="selectGovBgtEcoReport" v-model="govBgtEcoName" class="filter-item" clearable placeholder="--请选择--" style="width:100%" @clear="clearGovHandle">
                  <el-option :value="formData.govBgtEcoCode" :label="govBgtEcoName" style="height:200px;overflow: auto;background-color:#fff">
                    <el-tree
                      :data="govBgtEcoLists"
                      :accordion="true"
                      :highlight-current="true"
                      :props="defaultProps"
                      :node-key="defaultProps.id"
                      :default-expanded-keys="defaultExpandedKey"
                      @node-click="handleGovNodeClick"
                    />
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="5.5">
                <el-form-item label="扣减顺序" style="background-color: #f2f2f2" />
                <el-input-number :precision="0" v-model="tmpData.payOrder" :min="1" :max="999" />
              </el-col>
            </el-row>
            <el-row style="margin-top: 2%">
              <el-col>
                <el-button
                  size="small"
                  class="filter-item"
                  style="margin-left: 10px;"
                  type="primary"
                  @click="handleQueryIndexList"
                >
                  查询
                </el-button>
              </el-col>
            </el-row>
            <el-row style="margin-top: 2%">
              <el-col>
                <span>共匹配{{indexTotal}}条指标</span>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <u-table
                  ref="indexTable"
                  v-loading="indexLoading"
                  :data="indexList"
                  :stripe="true"
                  fit
                  style="width: 100%;  margin-left:10px"
                  height="300px"
                  :header-cell-style="{background:'#eef1f6',color:'#606266'}"
                  use-virtual
                  row-id = "bgtId"
                  beautifyTable
                  :big-data-checkbox="true"
                  fixed-columns-roll
                  highlight-current-row
                  inverse-current-row
                  header-drag-style
                  :border="false"
                >
                  <template slot="empty">
                    <tableEmpty />
                  </template>
                  <!-- <el-table-column type="selection" align="center" width="50" /> -->
                  <u-table-column label="指标ID" prop="bgtId" align="center" />
                  <u-table-column label="指标总金额" width="120" align="center">
                    <template slot-scope="{row}">
                      <span style="float: right">{{ Number(row.aviamt).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
                    </template>
                  </u-table-column>
                  <u-table-column label="剩余指标" width="120" align="center">
                    <template slot-scope="{row}">
                      <span style="float: right">{{ Number(row.canuseamt).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
                    </template>
                  </u-table-column>
                  <u-table-column label="支付方式" prop="payTypeName" width="120" align="center" />
                  <u-table-column label="功能分类编码" prop="expFuncCode" width="120" align="center" />
                  <u-table-column label="功能分类名称" prop="expFuncName" width="120" align="center" />
                  <u-table-column label="指标文号" prop="corBgtDocNoName" width="120" align="center" />
                  <u-table-column label="资金性质" prop="fundTypeName" width="120" align="center" />
                  <u-table-column label="预算项目" prop="proName" width="120" align="center" />
                  <u-table-column label="单位编码" prop="agency_code" width="120" align="center" />
                  <u-table-column label="单位名称" prop="agencyName" width="120" align="center" />
                  <u-table-column label="经济分类编码" prop="depBgtEcoNo" width="120" align="center" />
                  <u-table-column label="经济分类名称" prop="depBgtEcoName" width="120" align="center" />
                  <u-table-column label="政府经济科目" prop="gov_bgt_eco_name" width="120" align="center" />
                  <u-table-column label="支出类别" prop="pay_category_name" width="120" align="center" />                  
                </u-table>
                <!-- <pagination :total="indexTotal" :page.sync="formData.offset" :limit.sync="formData.limit" @pagination="getIndexList" /> -->
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col style="text-align: center; margin-top:2%">
            <el-button type="primary" :loading="saveLoading" @click="handleSaveHookUpData">
              确定
            </el-button>
            <el-button @click="hookUpFormVisible = false">
              取消
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { queryBgtSalaryBaseDataInfo, queryPersonType } from '@/api/salaryConfigManage/salaryProjectConnect'
import { queryAgencySalaryPaymentPage, queryRuleIndexPageRule, saveRuleHookUpData,
  getHookUpData } from '@/api/salaryConfigManage/connectIndex'
import { getAuthAgencyTree, getPayType, getProCat, getPro, getDepBgtEco, getPayCategory,getBaseDataFunc, getGovBgtEcoTree } from '@/api/baseInfo'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import tableEmpty from '@/components/table/empty'
import AgencyTree from '@/components/tree/agencyTree'
import Drag from '@/components/Drag'
export default {
  name: 'ConnectIndex',
  components: { Pagination, tableEmpty, AgencyTree, Drag },
  filters: {
    usingFilter(type) {
      if (type === '1') {
        return '启用'
      } else if (type === '0') {
        return '停用'
      }
    }
  },
  data() {
    return {
      defaultPropss: {
        children: 'children',
        label: 'label'
      },
      agencyTreeData: [], // 树数据集合
      treeHeight: null,
      isActive: true,
      Show: false,
      treeShow: false,
      treeData: '',
      tableHeight: null,
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 200,
        agencyId: '0'
      },
      payTypeLists: [], // 支付方式
      proCatLists: [], // 项目分类
      proLists: [], // 预算项目
      depBgtEcoLists: [], // 部门经济分类
      funcLists: [], // 支出功能分类科目
      govBgtEcoLists: [],// 政府经济分类
      payCategoryLists: [{ 'id': '11', 'label': '统发工资经费' }], // 工资类别
      hookUpFormVisible: false,
      indexLoading: false,
      usingList: [{ 'code': '1', 'name': '启用' }, { 'code': '0', 'name': '停用' }],
      indexList: [],
      indexTotal: 0,
      defaultProps: {
        id: 'id',
        children: 'children',
        label: 'label'
      },
      defaultExpandedKey: [],
      defaultPayExpandedKey: [11],
      // formData
      tmpData: {
        salaryId: '',
        columnName: '',
        columnNames: [],
        salaryBaseName: '',
        personType: '',
        payOrder:'1',
        salaryBaseDatas:[]
      },
      formData: {
        agencyIds: [],
        offset: '1',
        limit: '10000000',
        payTypeCode: '',
        proCatCode: '',
        proCode: '',
        corBgtDocNoName: '',
        depBgtEcoCode: '',
        payCategoryCode: '',
        govBgtEcoCode: '',
        funcCode:'',
        agencyId: ''
      },
      depBgtEcoName: '',
      payCategoryName: '',
      govBgtEcoName: '',
      
      funcName: '',
      hookUpQuery: {
        salaryId: '',
        personType: '',
        agencyId: ''
      },
      hookUpLoading: false,
      saveLoading: false,
      selection: [],
      hookUpList: [],
      checkSumIdList: [],
      personTypeData: [],
      salaryData: []
    }
  },
  watch: {
    list(val) {
      this.doLayout()
    }
  },
  created() {
    this.getList()
    this.initBaseInfo()
  },
  mounted() {
    this.getTbHeight()
    this.dragController()
    this.getTreeData()
    this.getqueryPersonType()
    this.queryBgtSalaryBaseDataInfo()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTbHeight)
  },

  methods: {
    getSalary(selected) {
      const tmp = this.salaryData.filter(item => {
        return selected.includes(item.salaryCode)
      })
      this.tmpData.salaryBaseDatas=tmp
      // this.tmpData.salaryId = tmp[0].id
      // this.tmpData.salaryBaseName = tmp[0].salaryName
    },
    // 工资项名称
    getqueryPersonType() {
      queryPersonType().then(respnse => {
        this.personTypeData = respnse.data
      })
    },
    // 工资项类别
    queryBgtSalaryBaseDataInfo() {
      queryBgtSalaryBaseDataInfo().then(response => {
        this.salaryData = response.data
      })
    },
    getTreeData() {
      getAuthAgencyTree().then(response => {
        this.agencyTreeData = response.data
      })
    },
    // 拖拽
    dragController() {
      this.$refs.icon.dragControllerDiv()
    },
    toggerTree() {
      this.treeShow = !this.treeShow
      this.isActive = !this.isActive
      this.Show = !this.Show
    },
    getFirstAuthAgencyData(data) {
      this.treeData = data
      this.handleTree(data)
    },
    handleTreeQuery(data) {
      this.treeData = data
      this.handleTree(data)
    },
    handleTree(data) {
      if (data.isleaf === '1') {
        this.listQuery.agencyId = data.id
        this.getList()
      }
    },
    /* 重新渲染table组件 */
    doLayout() {
      this.$nextTick(() => {
        this.$refs.singalTable.doLayout()
      })
    },
    // 获取table高度的方法
    getTbHeight() {
      this.tableHeight = window.innerHeight - 228
      this.treeHeight = window.innerHeight - 228
    },
    getList() {
      this.listLoading = true
      queryAgencySalaryPaymentPage(this.listQuery).then(response => {
       // 求和
        let result = [];
        response.data.rows.forEach(a => {
          if (!result.some(item => item.salaryBaseName === a.salaryBaseName && item.personStateName === a.personStateName )) {
            result.push(a)
          } else {
            result.map(item => {
              if (item.salaryBaseName === a.salaryBaseName && item.personStateName === a.personStateName) {
                item.aviamt = Number(item.aviamt)+  Number(a.aviamt)
                item.canuseamt =  Number(item.canuseamt) +  Number(a.canuseamt)
              }
            })
          }
        });
        this.list = result;
        //this.list = response.data.rows // 打开求和，就注销这一句
       // this.total = response.data.total
        this.total =this.list.length
        this.listLoading = false
      })
    },
    handleQuery() {
      this.listQuery.page = 1
      // this.listQuery.limit = 10
      this.getList()
    },
    // 指标挂接
    handleHookUp() {
      this.selection = []
      this.selection = this.$refs.singalTable.selection
      this.indexList = []
      this.indexTotal = 0
      this.hookUpList = []
      this.checkSumIdList = []
      this.hookUpFormVisible = true
      this.saveLoading = false
      // this.hookUpQuery.salaryId = this.selection[0].salaryId
      // this.hookUpQuery.personType = this.selection[0].personType
      // this.hookUpQuery.agencyId = this.selection[0].agencyId
      // this.formData.agencyId = this.selection[0].agencyId
      // 获取已挂接的指标
      this.getHookUpData()
    },
    getHookUpData() {
      this.hookUpLoading = true
      getHookUpData(this.hookUpQuery).then((response) => {
        this.hookUpList = response.data
        this.hookUpList.forEach(item => {
          this.checkSumIdList.push(item.bgtId)
        })
        this.hookUpLoading = false
      })
    },
    // 查询预算指标表格数据
    getIndexList() {
      this.indexLoading = true
      queryRuleIndexPageRule(this.formData).then((response) => {
        this.indexList = response.data.rows
        this.indexTotal = response.data.total
        this.indexLoading = false
      })
    },
    filterConditions(nodes){
      const CHECK_NODES = this.$refs.treee.getCheckedNodes()
      return CHECK_NODES.filter(item => { return !item.children }) && CHECK_NODES.filter(item => { return !item.children }).length > 0
    },
    // 查询预算指标表数据
    handleQueryIndexList() {
      this.formData.agencyIds=[]
      let agencys=this.$refs.treee.getCheckedNodes().filter(item => { return item.isleaf==1 })
      this.indexList=[]
      agencys.forEach(s => {
          this.formData.agencyIds.push(s.id)
        })

      this.formData.offset = 1
      this.formData.limit = 10000000
      this.getIndexList()
    },
    handleAllChecked(rows) { // 全选事件
      const _that = this
      if (rows.length === 0) {
        const rows2 = _that.indexList

        rows2.forEach(function(item) {
          _that.handleDeleteClick(item) // 删除
        })
      }
      rows.forEach(function(item) {
        _that.handleIndexChecked(rows, item)
      })
    },
    // 预算指标表点击复选框事件
    handleIndexChecked(rows, row) {
      // 如果rows有值，则进行判断，如果没有，直接删除row数据
      if (rows.length > 0) {
        // 如果rows里不包含当前选中的行数据，则为删除数据；否则为增加数据
        if (rows.indexOf(row) < 0) {
          if (this.hookUpList.length > 0) {
            for (const index in this.hookUpList) {
              if (this.hookUpList[index]['bgtId'] === row.bgtId) {
                this.hookUpList.splice(index, 1)
              }
            }
          }
          const checkedIndex = this.checkSumIdList.indexOf(row.bgtId)
          this.checkSumIdList.splice(checkedIndex, 1)
        } else {
          // 判断已挂接的是否存在选中的数据，如果不存在则添加
          let flag = false
          this.hookUpList.forEach(item => {
            if (item.bgtId === row.bgtId) {
              flag = true
            }
          })
          if (!flag) {
            this.hookUpList.push(row)
            this.checkSumIdList.push(row.bgtId)
          }
        }
      } else {
        const index = this.hookUpList.indexOf(row)
        this.hookUpList.splice(index, 1)
        const checkedIndex = this.checkSumIdList.indexOf(row.bgtId)
        this.checkSumIdList.splice(checkedIndex, 1)
      }
    },
    // 删除挂接表数据
    handleDeleteClick(row) {
      // 预算指标表的bgtId和删除的bgtId相同时，取消预算指标表的复选框
      const indexTableData = this.$refs.indexTable.tableData
      indexTableData.forEach(item => {
        if (item.bgtId === row.bgtId) {
          this.$refs.indexTable.toggleRowSelection(item, false)
        }
      })
      // 删除存储的挂接表数据
      const index = this.hookUpList.indexOf(row)
      this.hookUpList.splice(index, 1)
      const checkedIndex = this.checkSumIdList.indexOf(row.bgtId)
      this.checkSumIdList.splice(checkedIndex, 1)
    },
    // 保存
    handleSaveHookUpData() {
      this.saveLoading = true
      // if(this.tmpData.columnName===''||this.tmpData.columnName===null)
      if(this.tmpData.salaryBaseDatas.length === 0){
        this.$message({
          showClose: true,
          message: '请选择工资项！',
          type: 'warning',
          duration: 4000
        })
        this.saveLoading = false
        return
      }
      if(this.tmpData.personType===''||this.tmpData.personType===null){
        this.$message({
          showClose: true,
          message: '请选择工资类型！',
          type: 'warning',
          duration: 4000
        })
        this.saveLoading = false
        return
      }
      if(this.indexList.length==0){
        this.$message({
          showClose: true,
          message: '无可挂接信息！',
          type: 'warning',
          duration: 4000
        })
        this.saveLoading = false
        return
      }
      this.tmpData.bgtInfos = this.indexList
      saveRuleHookUpData(this.tmpData).then(res => {
        this.$message({
          showClose: true,
          message: '保存成功',
          type: 'success',
          duration: 4000
        })
        this.hookUpFormVisible = false
        this.handleQuery()
      })
      // this.saveLoading = true
      // const hookUpData = this.$refs.hookUpTable.tableData
      // this.selection[0]['bgtInfos'] = hookUpData
      // saveHookUpData(this.selection[0]).then((response) => {
      //   this.$message({
      //     showClose: true,
      //     message: '保存成功',
      //     type: 'success',
      //     duration: 4000
      //   })
      //   this.saveLoading = false
      //   this.hookUpFormVisible = false
      //   this.handleQuery()
      // }).catch(() => {
      //   this.saveLoading = false
      // })
    },
    // 树点击
    handleNodeClick(data) {
      if (data.isleaf === '1') {
        this.formData.depBgtEcoCode = data.code
        this.depBgtEcoName = data.label
        this.$refs.selectReport.blur()
      }
    },
    // 树点击
    handleFuncNodeClick(data) {
      if (data.isleaf === '1') {
        this.formData.funcCode = data.code
        this.funcName = data.label
        this.$refs.selectFuncReport.blur()
      }
    },
    // 清除下拉树选中
    clearHandle() {
      this.depBgtEcoName = ''
      this.formData.depBgtEcoCode = ''
      this.defaultExpandedKey = []
    },
    clearHandlePay(){
      this.formData.funcCode= ''
    },
    // 树点击
    handlePayNodeClick(data) {
      if (data.isleaf === '1') {
        this.formData.payCategoryCode = data.code
        this.payCategoryName = data.label
        this.$refs.selectPayReport.blur()
      }
    },
    //政府经济科目树点击
    handleGovNodeClick(data) {
      if (data.isleaf === '1') {
        this.formData.govBgtEcoCode = data.code
        this.govBgtEcoName = data.label
        this.$refs.selectGovBgtEcoReport.blur()
      }
    },
    // 清除工资类别下拉树
    clearPayHandle() {
      this.payCategoryName = ''
      this.formData.payCategoryCode = ''
      this.defaultPayExpandedKey = []
    },
    // 清除政府经济类别下拉树
    clearGovHandle() {
      this.govBgtEcoName = ''
      this.formData.govBgtEcoCode = ''
      this.defaultPayExpandedKey = []
    },
    
    // 初始化基础数据
    initBaseInfo() {
      // 支付方式
      getPayType().then((response) => {
        this.payTypeLists = Object.assign({}, response.data)
      })
      // 项目分类
      getProCat().then((response) => {
        this.proCatLists = Object.assign({}, response.data)
      })
     
      // 预算项目
      // getPro().then((response) => {
      //   this.proLists = Object.assign({}, response.data)
      // })
       // 支出功能分类科目
      getBaseDataFunc().then((response) => {
        this.funcLists = response.data
      })
      // 政府经济分类
      getDepBgtEco().then((response) => {
        this.depBgtEcoLists = response.data
      })
      // 工资类别
      getPayCategory().then((response) => {
        this.payCategoryLists = response.data
      })
      //政府性经济科目树
      getGovBgtEcoTree().then((response) => {
        this.govBgtEcoLists = response.data
      })
    },
    oninput(val,limit = 0) {
            val = val.replace(/[^\d.]/g, ""); //保留数字
            val = val.replace(/^00/, "0."); //开头不能有两个0
            val = val.replace(/^\./g, "0."); //开头为小数点转换为0.
            val = val.replace(/\.{2,}/g, "."); //两个以上的小数点转换成一个
            val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", "."); //只保留一个小数点
            /^0\d+/.test(val) ? val = val.slice(1) : ''; //两位以上数字开头不能为0
            const str = '^(\\d+)\\.(\\d{' + limit + '}).*$'
            const reg = new RegExp(str)
            if (limit === 0) {
                // 不需要小数点
                val= val.replace(reg, '$1')
            } else {
                // 通过正则保留小数点后指定的位数
                val= val.replace(reg, '$1.$2')
            }
            return val
        }
  }
}
</script>
<style lang="scss" scoped>
  .dialogFlex{
    display: flex;
  }
  .cell-input{
    width: 80%;
  }
  ::v-deep .indexTable {
    .el-table__header-wrapper {
      .el-checkbox {
        display: none;
      }
    }

  }
  ::v-deep.hookUpTable {
    .el-input{
      width: auto !important;
    }
  }
  ::v-deep.el-select-dropdown__item.selected {
    font-weight: normal;
  }
  .el-row-out {
    display: flex;
    flex-wrap: wrap;
    .el-tree-out {
      height: auto;
      max-height: 500px;
      overflow: auto;
    }
    .tipsCol {
      margin-top: 5%;
    }

    .tipsSpan {
      color: #ff0000;
      font-size: 18px;
      font-weight: 600;
    }
  }
</style>
